@extends('wap.layout.base')
@section('scripts')
    <script>
        let app = new Vue({
            el: '#app',
            data: function() {
                return {
                    title: '修改密码',
                    form: {
                        password_old: '',
                        password: '',
                        password_confirmation: '',
                        _token:"{{csrf_token()}}"
                    },
                }
            },
            methods: {
                onClickLeft() {
                    window.location.href = "{{ route('wap.user.index') }}";
                },
                update() {
                    let that = this;
                    if(!this.form.password_old){
                        this.$toast('请输入旧密码');
                        return false;
                    }
                    if(!this.form.password){
                        this.$toast('请输入新密码');
                        return false;
                    }
                    if(this.form.password.length<6){
                        this.$toast('密码的长度不能小于6位');
                        return false;
                    }
                    if(!this.form.password_confirmation){
                        this.$toast('请再次输入新密码');
                        return false;
                    }
                    if(this.form.password_confirmation != this.form.password){
                        this.$toast('新密码两次输入不一致');
                        return false;
                    }
                    $.post("{{ route('wap.user.password') }}",this.form,function(res){
                        if(res.code){
                            that.$toast(res.msg);
                        }else{
                            that.$toast.loading({
                                duration: 0,       // 持续展示 toast
                                forbidClick: true, // 禁用背景点击
                                loadingType: 'spinner',
                                message: '重置密码成功'
                            });
                            setTimeout(function(){
                                that.$toast.clear();
                                window.location.href = "{{ route('wap.user.index') }}";
                            }, 1000);
                        }
                    });
                },
            }
        });
    </script>
@endsection
@section('content')
    <div class="container main user-detail" id="app" v-cloak>
        <div class="row">
            <van-nav-bar
                    :title="title"
                    left-text=""
                    border
                    fixed="true"
                    left-arrow="false"
                    @click-left="onClickLeft">
                <van-icon name="arrow-left" slot="left"/>
            </van-nav-bar>
            <div class="col-xs-12">
                <van-cell-group>
                    <van-field input-align="right" type="password" required v-model="form.password_old" label="旧密码" placeholder="请输入旧密码"/>
                </van-cell-group>
                <van-cell-group>
                    <van-field input-align="right" type="password" required v-model="form.password" label="新密码" placeholder="请输入新密码"/>
                </van-cell-group>
                <van-cell-group>
                    <van-field input-align="right" type="password" v-model="form.password_confirmation" required label="确认密码" placeholder="请再次输入新密码"/>
                </van-cell-group>
                <p class="form-submit" style="margin-top: 2rem">
                    <van-button type="default" @click="update()">保存提交</van-button>
                </p>
            </div>
        </div>
    </div>
@endsection

